# Definition for a binary tree node.
class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


class FindElements:

    def __init__(self, root: TreeNode):
        self.memo = set()
        root.val = 0
        self.memo.add(0)
        self.__fix(root)

    def find(self, target: int) -> bool:
        return target in self.memo

    def __fix(self, root: TreeNode):
        if root is None:
            return
        if root.left:
            root.left.val = 2 * root.val + 1
            self.memo.add(root.left.val)
            self.__fix(root.left)
        if root.right:
            root.right.val = 2*root.val + 2
            self.memo.add(root.right.val)
            self.__fix(root.right)
